package com.example.lawyer.databind.assembly;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.example.lawyer.BR;
import com.example.lawyer.R;
import com.example.lawyer.adapter.CurrentAdapters;
import com.example.lawyer.databind.itemview.MessageListItemViewData;

import java.util.List;

public class MessageListData {

    public ObservableField<List<MessageListItemViewData>> listitemdata = new ObservableField<>();


    public void itemclick() {
        System.out.println("点击有效");
    }


    @BindingAdapter("setAdapterList")
    public static void SetAdapter(View view, List<MessageListItemViewData> data) {
        if (data != null) {
            CurrentAdapters adapters = new CurrentAdapters(data, R.layout.item_message_view, BR.msglistitem);
            ListView listView = (ListView) view;
            listView.setAdapter(adapters);
        }
    }

    /***
     * 监听事件
     */
    @BindingAdapter("itemselect")
    public static void ItemSelect(View view, List<MessageListItemViewData> data) {
        final Context context = view.getContext();

        ListView listView = (ListView) view;
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println("点击有效");
                System.out.println(parent.getItemAtPosition(position));

                Intent intent = new Intent();
                intent.setAction("chat");
                context.startActivity(intent);
            }
        });
    }
}
